﻿// ./about/About.cpp : 实现文件
//
#include "stdafx.h"
#include "tabUi.h"
#include <ossDir.h>
#include <ossDll.h>
#include <ossString.h>
#include <ossList.h>
#include "labelDeviceBase.hpp"


IMPLEMENT_DYNAMIC(tabUi, LabelUiBase)

#define TAB_CTRL_ID            0x0200
tabUi::tabUi(LabelUiBase* pParentFenceUi,const char* pcDeviceId)
    :LabelUiBase(pParentFenceUi,pcDeviceId)
{
  
}

tabUi::~tabUi()
{
}

BEGIN_MESSAGE_MAP(tabUi, LabelUiBase)
	ON_NOTIFY(TCN_SELCHANGE, TAB_CTRL_ID, &tabUi::OnTcnSelchangeTabControlButton)
    ON_WM_SIZE()
    ON_WM_CREATE()
END_MESSAGE_MAP()



// About 消息处理程序
int tabUi::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (LabelUiBase::OnCreate(lpCreateStruct) == -1)
        return -1;

	m_font.CreatePointFont(135, _T("微软雅黑"));
	m_tabControl.Create(TCS_TABS|WS_CHILD|WS_VISIBLE,CRect(0, 0, 0, 0),this,TAB_CTRL_ID);
	m_tabControl.SetFont(&m_font);

    return 0;
}


void tabUi::OnSize(UINT nType, int cx, int cy)
{
	//LabelUiBase *pUi;
	//OssListForEachEntry(pUi,&m_childUi,m_childUiNode,LabelUiBase)
	//{
	//	pUi->MoveWindow(0,40,cx,cy-40);
	//}

    //LabelUiBase::OnSize(nType, cx, cy);
	if (m_tabControl.GetItemCount() != m_iChildUiNum)
	{
		LabelUiBase* pUi;
		int iIndex = 0;

		m_tabControl.DeleteAllItems();
		OssListForEachEntry(pUi,&m_childUi,m_childUiNode,LabelUiBase)
		{
			m_tabControl.InsertItem(iIndex,pUi->GetTitle());  
			iIndex ++;
		}

		m_tabControl.SetCurSel(0);
		SetShowTab(0);
	}
	m_tabControl.MoveWindow(0, 0, cx, 40, TRUE);

}

void tabUi::OnTcnSelchangeTabControlButton(NMHDR *pNMHDR, LRESULT *pResult)
{
	SetShowTab(m_tabControl.GetCurSel());
}

void tabUi::SetShowTab(int iShow)
{
	int iIndex = 0;
	LabelUiBase* pUi;
	CRect rect;
	GetClientRect(rect);
	OssListForEachEntry(pUi,&m_childUi,m_childUiNode,LabelUiBase)
	{
		if (iIndex == iShow)
		{
			pUi->MoveWindow(0,40,rect.Width(),rect.Height()-40);
			pUi->ShowWindow(SW_SHOW);
		}
		else
		{
			pUi->MoveWindow(0,0,0,0);
			pUi->ShowWindow(SW_HIDE);
		}
		iIndex ++;
	}
}

static OssVersion g_version={
	"V2.0.0.0",
	"tabUi",
	"吴建凰",
	__DATE__,
	"创建tab驱动界面 吴建凰 2021年10月4日\n"   //不能加逗号，多次信息一次增加
	"\n\n"
};

LABEL_UI_ENTRY(tabUi)

